package com.ymatou.iapi.deviceid.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.deviceid.parameter.SaveBean;
import com.ymatou.iapi.deviceid.parameter.device;
import com.ymatou.iapi.deviceid.parameter.devicelist;
import com.ymatou.iapi.deviceid.parameter.getListBean;
import com.ymatou.iapi.deviceid.service.getListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DeviceidCallService;
/**
*获取一组DeviceId信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getList{
	private static getListBean getlistBean;
	private static getListCall getlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取一组DeviceId信息");
	}

	@Before
	public void caseUp() {
		getlistBean=new getListBean();
		getlistCall=new getListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_001() {
		Logger.start(true,"获取一组DeviceId信息-单条");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setMachinename("iphoneX");
			DeviceidCallService.saveCall(saveBean1);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			getlistBean.setType(1);
			getlistBean.setLimit(20);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("0", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(getlistBean.getUserid()+" exists", getlistCall.getMSG(), "验证返回msg");
			
			devicelist devicelist = getlistCall.getReturnList();
			
			Logger.verifyEquals(1, devicelist.getData().size(), "验证返回一条数据");
			
			device device = devicelist.getData().get(0);
			
			Logger.verifyEquals(saveBean1.getDeviceid(), device.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getDid(), device.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getClienttype(), device.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device.getSuccess(), "验证返回Deviceid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_002() {
		Logger.start(true,"获取一组DeviceId信息-多条-降序");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean1);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setUserid(saveBean1.getUserid());
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			getlistBean.setType(1);
			getlistBean.setLimit(20);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("0", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(getlistBean.getUserid()+" exists", getlistCall.getMSG(), "验证返回msg");
			
			devicelist devicelist = getlistCall.getReturnList();
			
			Logger.verifyEquals(2, devicelist.getData().size(), "验证返回一条数据");
			
			device device = devicelist.getData().get(0);
			
			Logger.verifyEquals(saveBean2.getDeviceid(), device.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean2.getDid(), device.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean2.getClienttype(), device.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device.getSuccess(), "验证返回Deviceid");
			
			device device2 = devicelist.getData().get(1);
			
			Logger.verifyEquals(saveBean1.getDeviceid(), device2.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getDid(), device2.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getClienttype(), device2.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device2.getSuccess(), "验证返回Deviceid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_003() {
		Logger.start(true,"获取一组DeviceId信息-多条-升序");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean1);
			
			Thread.sleep(1000);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setUserid(saveBean1.getUserid());
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			getlistBean.setType(0);
			getlistBean.setLimit(20);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("0", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(getlistBean.getUserid()+" exists", getlistCall.getMSG(), "验证返回msg");
			
			devicelist devicelist = getlistCall.getReturnList();
			
			Logger.verifyEquals(2, devicelist.getData().size(), "验证返回一条数据");
			
			device device = devicelist.getData().get(0);
			
			Logger.verifyEquals(saveBean1.getDeviceid(), device.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getDid(), device.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getClienttype(), device.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device.getSuccess(), "验证返回Deviceid");
			
			device device2 = devicelist.getData().get(1);
			
			Logger.verifyEquals(saveBean2.getDeviceid(), device2.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean2.getDid(), device2.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean2.getClienttype(), device2.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device2.getSuccess(), "验证返回Deviceid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_004() {
		Logger.start(true,"获取一组DeviceId信息-多条-升序,验证Limit生效");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean1);
			
			Thread.sleep(1000);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setUserid(saveBean1.getUserid());
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			getlistBean.setType(0);
			getlistBean.setLimit(1);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("0", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(getlistBean.getUserid()+" exists", getlistCall.getMSG(), "验证返回msg");
			
			devicelist devicelist = getlistCall.getReturnList();
			
			Logger.verifyEquals(1, devicelist.getData().size(), "验证返回一条数据");
			
			device device = devicelist.getData().get(0);
			
			Logger.verifyEquals(saveBean1.getDeviceid(), device.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getDid(), device.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getClienttype(), device.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device.getSuccess(), "验证返回Deviceid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_005() {
		Logger.start(true,"获取一组DeviceId信息-userid空");
		try {

			getlistBean.setType(0);
			getlistBean.setLimit(1);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("100", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("userid必须大于零", getlistCall.getMSG(), "验证返回msg");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_006() {
		Logger.start(true,"获取一组DeviceId信息-type空默认0");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean1);
			
			Thread.sleep(1000);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setUserid(saveBean1.getUserid());
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			//getlistBean.setType(0);
			getlistBean.setLimit(1);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("0", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(getlistBean.getUserid()+" exists", getlistCall.getMSG(), "验证返回msg");
			
			devicelist devicelist = getlistCall.getReturnList();
			
			Logger.verifyEquals(1, devicelist.getData().size(), "验证返回一条数据");
			
			device device = devicelist.getData().get(0);
			
			Logger.verifyEquals(saveBean1.getDeviceid(), device.getDeviceid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getDid(), device.getDid(), "验证返回Deviceid");
			Logger.verifyEquals(saveBean1.getClienttype(), device.getClienttype(), "验证返回Deviceid");
			Logger.verifyEquals(true, device.getSuccess(), "验证返回Deviceid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getList_007() {
		Logger.start(true,"获取一组DeviceId信息-type取不正确值");
		try {

			SaveBean saveBean1 = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean1);
			
			Thread.sleep(1000);
			
			SaveBean saveBean2 = DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setUserid(saveBean1.getUserid());
			DeviceidCallService.saveCall(saveBean2);
			
			getlistBean.setUserid(saveBean1.getUserid());
			getlistBean.setType(2);
			getlistBean.setLimit(1);
			
			getlistCall.setData(getlistBean);
			getlistCall.callService();	
			
			Logger.verifyEquals("100", getlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("type必须是0或者1", getlistCall.getMSG(), "验证返回msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}